function rate_modifier(arith) {
 $modifier = document.InvoiceProperties.RTModPoint.value;
 if ($modifier > 0 && $modifier <= (document.InvoiceProperties.RTModDefPoint.value*2) && arith == 'add' || $modifier >= 0 && $modifier < (document.InvoiceProperties.RTModDefPoint.value*2) && arith == 'sub') {
 $modifier = document.InvoiceProperties.RTModPoint.value;
	$modif = 0.0001;
	if (arith == 'sub') {
	$modif = $modif*(-1);
	}
	document.InvoiceProperties.FraTasa.value = (parseFloat(document.InvoiceProperties.FraTasa.value)+$modif).toFixed(4);
	document.InvoiceProperties.RTModPoint.value = $modifier-$modif*10000;
	}
 $modifier = document.InvoiceProperties.RTMod.value;
 if ($modifier > 0 && $modifier <= (document.InvoiceProperties.RTModDef.value*2) && arith == 'add100' || $modifier >= 0 && $modifier < (document.InvoiceProperties.RTModDef.value*2) && arith == 'sub100') {
 $modifier = document.InvoiceProperties.RTMod.value;
	$modif = 0.0100;
	if (arith == 'sub100') {
	$modif = $modif*(-1);
	}
	document.InvoiceProperties.FraTasa.value = (parseFloat(document.InvoiceProperties.FraTasa.value)+$modif).toFixed(4);
	document.InvoiceProperties.RTMod.value = $modifier-$modif*10000;
	}
	InvoiceCalc();
}
function InvoiceCalc() {
	$ORHTSent = parseFloat(document.InvoiceProperties.AntFraEnviado.value);
	$ORHTPay = parseFloat(document.InvoiceProperties.AntFraARecibir.value);
	$ORHTProm = parseFloat(document.InvoiceProperties.AntFraProm.value);
	
	$ORSent = parseFloat(document.InvoiceProperties.FraEnviado.value);
	$ORRate = parseFloat(document.InvoiceProperties.FraTasa.value);
	$ORProm = parseFloat(document.InvoiceProperties.FraProm.value);
	
	// Taxes
		$TaxType = document.InvoiceProperties.TaxPay.value;
		
		$ORHTTax = document.InvoiceProperties.AntFraCargo.value;
		$ORHTTaxProm = document.InvoiceProperties.AntFraTaxProm.value;
		
		$ORTax = parseFloat(document.InvoiceProperties.FraCargo.value)-$ORHTTax+parseFloat(document.InvoiceProperties.FraCargo.value);
		$ORTaxProm = parseFloat(document.InvoiceProperties.FraTaxProm.value)-$ORHTTaxProm+parseFloat(document.InvoiceProperties.FraTaxProm.value);
		
		$ORTax = parseFloat($ORTax)-parseFloat($ORTaxProm);
	
	// Results
	$ORPay = ($ORSent-$ORTax)*$ORRate;
	$ORSent = $ORSent-$ORProm;
	
	if ($TaxType == 0) {
		if ($ORHTSent == $ORSent+$ORTax) {
		$ORSent = $ORSent-$ORTax;	
		}
		if ($ORHTPay == $ORPay-$ORTax) {
		$ORPay = $ORPay+($ORTax*$ORRate);
		}
	}
	if ($TaxType == 1) {
		if ($ORHTSent == $ORSent-$ORTax) {
		$ORSent = $ORSent+$ORTax;	
		}
		if ($ORHTPay == $ORPay+$ORTax) {
		$ORPay = $ORPay-($ORTax*$ORRate);
		}
	}
	
	document.InvoiceProperties.FraARecibir.value = $ORPay.toFixed(2);
	document.InvoiceProperties.FraEnviado.value = $ORSent;
	document.InvoiceProperties.FraCargo.value = $ORTax;
	
	 // Hist
	 document.InvoiceProperties.AntFraARecibir.value = $ORPay.toFixed(2);
	 document.InvoiceProperties.AntFraEnviado.value = $ORSent;
	 document.InvoiceProperties.AntFraCargo.value = $ORTax;
	 document.InvoiceProperties.AntFraProm.value = $ORProm;
	 document.InvoiceProperties.AntFraTaxProm.value = $ORTaxProm;
	
	if (document.InvoiceProperties.FraARecibir.value > 0) {
		document.InvoiceProperties.PRSVOR.disabled = false;
	} else {
		document.InvoiceProperties.PRSVOR.disabled = true;
	}
}
function TaxCalc() {
	
}
function MdRate() {
	$TasaAgn = parseFloat(document.InvoiceProperties.FraTasaAgn.value);
	$RTPts = parseFloat(document.InvoiceProperties.PTMod.value)/parseFloat(100);
	document.InvoiceProperties.RTMod.value = (parseFloat($TasaAgn)+parseFloat($RTPts)).toFixed(4);
}
function PopInvoice() {
	if (document.InvoiceProperties.htr_ID.value == '') {
	document.InvoiceProperties.PRSVOR.disabled = true;
	} else {
	document.InvoiceProperties.PRSVOR.disabled = false;
	}
}
function UnPopInvoice() {
	if (document.InvoiceProperties.FraTasa.value > 0) {
	replaceUrl('inv_Calc','Modules/XFK0WK2A/elem_clc.mex');
	document.getElementById('inv_Result').innerHTML='';
	document.InvoiceProperties.FraEnviado.value = '';
	document.InvoiceProperties.FraEnviado.value = '';
	document.InvoiceProperties.FraARecibir.value = '';
	document.InvoiceProperties.FraTasa.value = '';
	document.InvoiceProperties.FraComisionCorr.value = 0;
	document.InvoiceProperties.FraComisionAg.value = 0;
	document.InvoiceProperties.FraTasaAgn.value = '';
	document.InvoiceProperties.FraEntregue.value = '';
	document.InvoiceProperties.PRSVOR.disabled = true;
	}
}